﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace _03_WebRequest_WebResponce
{
    class Program
    {
        static void Main(string[] args)
        {
            //WebRequest request = WebRequest.Create("http://www.google.com");
            WebRequest request = WebRequest.Create("http://download.teamviewer.com/download/TeamViewer_Setup_uk-ckq.exe");
            
            WebResponse response = request.GetResponse();
            

            StreamReader stream = new StreamReader(response.GetResponseStream());
            
            Console.WriteLine("Length: {0}; Type: {1}", response.ContentLength/1024/1024.0, response.ContentType);
            
            // Barabashka was here
            
            BinaryReader br = new BinaryReader(response.GetResponseStream(), stream.CurrentEncoding);
            File.WriteAllBytes("../../file.exe", br.ReadBytes((int)response.ContentLength));
           
            //br.Dispose();
            br.Close();
           

            stream.Close();
            response.Close();
        }
    }
}
